#rm -rf TEST
#make clean
#make server
#make client
#make server-admin
#make genuid
#mkdir TEST
choices=7
cd TEST
../genuid 30
gnome-terminal --command="bash -c '../server --choices=$choices; echo hit ENTER...; read'"
sleep 2
# this voter tries to register before election has begun this attempt will fail.
# however he can register later without any problem again. To show this we
# have K0 who will not register and K12 who will and continue to successfully
# participate in the election.
../client --uid=0 --passwd=`cat 0` --keyfile=K0 --reg
../client --uid=12 --passwd=`cat 12` --keyfile=K12 --reg
sleep 1
../server-admin --reg
sleep 1
# try agin. this time K12 will succeed.
../client --uid=12 --passwd=`cat 12` --keyfile=K12 --reg
# these 4 clients will be able to successully register
../client --uid=1 --passwd=`cat 1` --keyfile=K1 --reg
../client --uid=2 --passwd=`cat 2` --keyfile=K2 --reg
../client --uid=3 --passwd=`cat 3` --keyfile=K3 --reg
../client --uid=4 --passwd=`cat 4` --keyfile=K4 --reg
# provide bad usernames and passwords both will not be able to get through
../client --uid=2000 --passwd=`cat 3` --keyfile=K2000 --reg
../client --uid=5 --passwd=`cat 41` --keyfile=K5 --reg
# try to register again, should be rejected but will still 
# be able to vote due to successful registration earlier.
../client --uid=4 --passwd=`cat 4` --keyfile=K4XXX --reg
# this voter will not send his tally key
../client --uid=6 --passwd=`cat 6` --keyfile=K6 --reg
# this voter will not vote
../client --uid=7 --passwd=`cat 7` --keyfile=K7 --reg
# will not send his secret key
../client --uid=8 --passwd=`cat 8` --keyfile=K8 --reg
# will send his secret key multiple times
../client --uid=9 --passwd=`cat 9` --keyfile=K9 --reg
# will caste illegal ballots
../client --uid=10 --passwd=`cat 10` --keyfile=K10 --reg
../client --uid=11 --passwd=`cat 11` --keyfile=K11 --reg

# the following will show up as registered to vote in progress:
# 1 2 3 4 6 7 8 9 10 11 12
# note that 0, 5 and 2000 are not listed.

sleep 1
../server-admin --tally-keys
sleep 1
# bad keyfile, should not crash
../client --keyfile=K0 --tally-key
# let's try a key conflict
# now this key (K3) will be blocked
../client --keyfile=K3 --tally-key
../client --keyfile=K3 --tally-key
# all the rest will work again without problem.
../client --keyfile=K1 --tally-key
../client --keyfile=K2 --tally-key
../client --keyfile=K4 --tally-key
# K6 is not providing his tallying key
../client --keyfile=K7 --tally-key
../client --keyfile=K8 --tally-key
../client --keyfile=K9 --tally-key
../client --keyfile=K10 --tally-key
../client --keyfile=K11 --tally-key
../client --keyfile=K12 --tally-key

# there will be 10 tallying keys with 1 disabled (that of K3)
# K0 does not have a key to provide.

sleep 1
../server-admin --vote
sleep 1

# try using bad keyfile, just to see that we do not throw up
../client --keyfile=K0 --vote=0
# a voter who cannot make up his mind, only the last vote counted.
../client --keyfile=K1 --vote=0
../client --keyfile=K1 --vote=1
../client --keyfile=K1 --vote=2
../client --keyfile=K1 --vote=3
# K2 drops out
# K3 is blocked so his vote will be rejected.
../client --keyfile=K3 --vote=3
# bad ballots, only 7 choices available
../client --keyfile=K10 --vote=1000
../client --keyfile=K11 --vote=-1
# try to vote without sending the tallying key.
../client --keyfile=K6 --vote=4
# K7 will not vote but will try to send the voting key and fail.
# voting key is only present in the key file if you vote.
# the following will have no problem.
../client --keyfile=K4 --vote=3
../client --keyfile=K8 --vote=4
../client --keyfile=K9 --vote=5
../client --keyfile=K12 --vote=5

# at the end of this phase two more tallying keys show up as
# having invalid IV,Kv(B)'s (K2 and K7). K3 also has an invalid
# vote since he is blocked. Note that though K10 and K11 caste
# illegal ballots their encrypted ballots are considered valid.

#sleep 2
#../server-admin --done
#exit

sleep 1
../server-admin --tally
sleep 1
# try using bad keyfile
../client --keyfile=K0 --tally
../client --keyfile=K1 --tally
# K3 is blocked
../client --keyfile=K3 --tally
../client --keyfile=K4 --tally
# try to again send the secret key without sending the tallying key
../client --keyfile=K6 --tally
# K7 does not have a voting key to send so will fail.
../client --keyfile=K7 --tally
# K8 won't send his secrety key.
# try sending the tally key multiple times no problem.
../client --keyfile=K9 --tally
../client --keyfile=K9 --tally
../client --keyfile=K9 --tally
../client --keyfile=K9 --tally
# K10 and K12 caste illegal ballots
../client --keyfile=K10 --tally
../client --keyfile=K11 --tally
# K12 no problem.
../client --keyfile=K12 --tally

# only the following voters will count at the end: K1(3), K4(3), K9(5), K12(5)
# RESULTS:
# 0 - 0
# 1 - 0
# 2 - 0
# 3 - 2
# 4 - 0
# 5 - 2
# 6 - 0
# rejected= 2, count_all= 6

sleep 1
# its all done!
../server-admin --done


